package com.duan.laugh.mp.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.duan.laugh.common.core.util.R;
import com.duan.laugh.mp.api.pojo.entity.MpFansMsgRes;
import com.duan.laugh.mp.service.IMpFansMsgResService;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * 微信粉丝消息回复管理
 *
 * @author duanjw
 * @date 2019-03-27 20:45:48
 */
@RestController
@AllArgsConstructor
@RequestMapping("/wxfansmsgres")
public class MpFansMsgResController {

    private final IMpFansMsgResService IMpFansMsgResService;

    /**
     * 分页查询
     *
     * @param page         分页对象
     * @param wxFansMsgRes 回复
     * @return
     */
    @GetMapping("/page")
    public R getWxFansMsgResPage(Page page, MpFansMsgRes wxFansMsgRes) {
        return R.ok(IMpFansMsgResService.page(page, Wrappers.query(wxFansMsgRes)));
    }


    /**
     * 通过id查询回复
     *
     * @param id id
     * @return R
     */
    @GetMapping("/{id}")
    public R getById(@PathVariable("id") Integer id) {
        return R.ok(IMpFansMsgResService.getById(id));
    }

    /**
     * 新增回复
     *
     * @param wxFansMsgRes 回复
     * @return R
     */
    @PostMapping
    public R save(@RequestBody MpFansMsgRes wxFansMsgRes) {
        return IMpFansMsgResService.saveAndSend(wxFansMsgRes);
    }

    /**
     * 修改回复
     *
     * @param wxFansMsgRes 回复
     * @return R
     */
    @PutMapping
    @PreAuthorize("@pms.hasPermission('mp_wxfansmsgres_edit')")
    public R updateById(@RequestBody MpFansMsgRes wxFansMsgRes) {
        return R.ok(IMpFansMsgResService.updateById(wxFansMsgRes));
    }

    /**
     * 通过id删除回复
     *
     * @param id id
     * @return R
     */
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('mp_wxfansmsgres_del')")
    public R removeById(@PathVariable Integer id) {
        return R.ok(IMpFansMsgResService.removeById(id));
    }

}
